//
//  AppDelegate.m
//  Entertainment
//
//  Created by dllo on 16/4/19.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "AppDelegate.h"
#import "RootNavigationController.h"
#import "RootTabBarViewController.h"
#import "FDMFindViewController.h"
#import "FDMTakeViewController.h"
#import "FDMDownloadViewController.h"
#import "FDMUserInfoViewController.h"
#import "FDMCurrentViewController.h"

#import "LTIntroductionViewController.h"

@interface AppDelegate ()

@property (nonatomic, retain) LTIntroductionViewController *firstLog;/**< 声明 */


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    [self createTabBarController];
    [_window release];
    
    /** 判断是否是第一次进入----- 记录状态 */
    NSString *firstLog = [[NSUserDefaults standardUserDefaults] objectForKey:@"firstLog"];
    /** YES是登录状态，如果！YES，那就是没有登录过（首次登录） */
    if (![firstLog isEqualToString:@"YES"]) {
        NSArray *mainImage = @[@"one", @"two", @"three"];
        NSArray *backImage = @[@"1", @"2", @"3.jpg"];
        self.firstLog = [[LTIntroductionViewController alloc] initWithCoverImageNames:mainImage backgroundImageNames:backImage];
        [self.window addSubview:_firstLog.view];
        [_firstLog release];
        /** 进入后 记录第一次进入的状态 */
        [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"firstLog"];
    }
    /** 点击引导页Enter按钮，引导页消失 */
//    _weak typedef (self)weakself = self;
    _firstLog.didSelectedEnter = ^() {
        
        [_firstLog.view removeFromSuperview];
        _firstLog = nil;
    };
//    sleep(1);
    
    
    return YES;
}

- (void)createTabBarController {
    RootTabBarViewController *rootTabBar = [[RootTabBarViewController alloc] init];
    rootTabBar.viewControllers = [self createRootNavs];
    rootTabBar.tabBar.translucent = NO;
    self.window.rootViewController = rootTabBar;
    [rootTabBar release];
}

- (NSArray <UINavigationController *>*)createRootNavs {
    
    NSMutableArray *arr = [NSMutableArray array];
    FDMFindViewController *findVc = [[FDMFindViewController alloc] init];
    RootNavigationController *findNav = [[RootNavigationController alloc] initWithRootViewController:findVc];
    findNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@""] tag:1000];
    [arr addObject:findNav];
    [findVc release];
    [findNav release];
    
    FDMTakeViewController *takeVc = [[FDMTakeViewController alloc] init];
    RootNavigationController *takeNav = [[RootNavigationController alloc] initWithRootViewController:takeVc];
    takeNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"订阅" image:[UIImage imageNamed:@""] tag:2000];
    [arr addObject:takeNav];
    [takeVc release];
    [takeNav release];
    
    FDMCurrentViewController *currentVc = [[FDMCurrentViewController alloc] init];
    RootNavigationController *currentNav = [[RootNavigationController alloc] initWithRootViewController:currentVc];
    currentNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@""] tag:3000];
    [arr addObject:currentNav];
    [currentVc release];
    [currentNav release];
    
    FDMDownloadViewController *downloadVc = [[FDMDownloadViewController alloc] init];
    RootNavigationController *downloadNav = [[RootNavigationController alloc] initWithRootViewController:downloadVc];
    downloadNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@""] tag:4000];
    [arr addObject:downloadNav];
    [downloadVc release];
    [downloadNav release];
    
    FDMUserInfoViewController *userVc = [[FDMUserInfoViewController alloc] init];
    RootNavigationController *userNav = [[RootNavigationController alloc] initWithRootViewController:userVc];
    userNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@""] tag:5000];
    [arr addObject:userNav];
    [userVc release];
    [userNav release];
    
    return arr;
}

- (void)dealloc {
    [_window release];
    [super dealloc];
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
